<?php
// Copyright 2004-2006 Won-Kyu Park <wkpark at kldp.org>
// All rights reserved. Distributable under GPL see COPYING
// a sample plugin for the MoniWiki
//
// Usage: [[Note]]
//
// $Id: Note.php,v 1.2 2003/08/15 21:30:36 wkpark Exp $

function macro_Note($formatter,$value) {
    global $DBInfo;

    $imgdir=$DBInfo->imgs_dir;
    $iconset='red';
    $full_width=0;

    # parse args
    $desc=array();
    $state=array();
    $state2=array();
    $items=explode(',',$value);
    foreach ($items as $item) {
        $p=strrpos($item,' ');
        $desc[]=substr($item,0,$p);
        $dum=trim(substr($item,$p+1));
        # make percent value
        if (substr($dum,-1) == '%') {
            $val=substr($dum,0,-1);
            if ($val > 100.0) $val=100;
        } else {
            if ($dum > 1.0) $val=100;
            else $val=$dum*100.0;
        }

        $ival=0;
        if ($val < 100.0) $ival=100.0 - $val;
        $img="<div style='white-space: nowrap'><img src='$imgdir/vote/$iconset/b_leftbar.gif' />";
        $img.="<img src='$imgdir/vote/$iconset/b_mainbar.gif' ".
            "height='14' width='$val%' />";
        if ($full_width && $ival != 0) {
            $img.="<img src='$imgdir/vote/$iconset/mainbar.gif' ".
                " height='14' width='$ival%' />";
            $img.="<img src='$imgdir/vote/$iconset/rightbar.gif' />";
        } else {
            $img.="<img src='$imgdir/vote/$iconset/b_rightbar.gif' />";
        }
        $state[]=$img.'</div>';
        $state2[]=((int)$val).'%';
    }

    $row='<table border="1" width="100%"><tr><td>desc</td><td width="80%">state</td><td>%</td></tr>';
    $sz=sizeof($desc);
    for ($i=0;$i<$sz;$i++) {
        $row.='<tr>';
        $row.='<td>'.$desc[$i].'</td>';
        $row.='<td>'.$state[$i].'</td>';
        $row.='<td>'.$state2[$i].'</td>';
        $row.='</tr>';
    }
#    for ($d=1;$d<=30;$d++) {
#        $row.='<td>'.$d.'</td>';
#    }
#    for ($i=1;$i<10;$i++) {
#        $row.='<tr>';
#        for ($d=1;$d<=30;$d++) {
#            $row.='<td>'.$d.'</td>';
#        }
#        $row.="</tr>\n";
#    }
    $row.="</table>\n";
    return $row;
}

// vim:et:sts=4:sw=4:

?>
